/*************************************************************************
	> File Name: hzoj_264.cpp
	> Author: 
	> Mail: 
	> Created Time: Sun 11 Aug 2024 09:55:31 AM CST
 ************************************************************************/

#include<iostream>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX_N 100000


int main() {
	int n;
	cin >> n;
	vector<long long> arr(n + 2, -1), l(n + 2), r(n + 2);
	stack<long long> ss;
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	for(int i = 1; i <= n + 1; i++) {
		while (!ss.empty() && arr[i] < arr[ss.top()]) {
			r[ss.top()] = i;
			ss.pop();
		}
		ss.push(i);
	}
	while(!ss.empty()) ss.pop();
	 for(int i = n; i >= 0; i--) {
		while (!ss.empty() && arr[i] < arr[ss.top()]) {
			l[ss.top()] = i;
			ss.pop();
		}
		ss.push(i);
	}
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		long long s = arr[i] * (r[i] - l[i] - 1);
		ans = max(ans, s);
	}
	cout << ans << endl;
	return 0;
}



/************************************************************
long long h[MAX_N + 5];
int l[MAX_N + 5], r[MAX_N + 5];

int main() {
	int n;
	stack<int> ss;
	// ss.push(-1);
	cin >> n;
	h[0] = h[n + 1] = -1;
	for(int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	ss.push(0);
	for(int i = 1; i <= n; i++) {
		while(h[ss.top()] >= h[i]) ss.pop();
		l[i] = i - ss.top();
		ss.push(i);
	}
	ss.push(n + 1);
	// cout << ss.top() << " " << h[ss.top()] << endl; // 调试
	for(int i = n; i >= 1; --i) {
		while(h[ss.top()] >= h[i]) ss.pop();
		r[i] = ss.top() - i;
		ss.push(i);
	}
	// for(int i = 1; i <= n; i++) {
	// 	cout << l[i] << " ";
	// } 
	// cout << endl;
	// for(int i = 1; i <= n; i++) {
	// 	cout << r[i] << " ";
	// } 
	// cout << endl;
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		int len = r[i] + l[i] - 1;
		ans = max(ans, h[i] * len);
	}
	cout << ans << endl;
	return 0;
}
***********************************************/
